//
//  DAUMonElectricityVC.m
//  DAU-iOS
//
//  Created by XiangDongMBP on 2016/11/18.
//  Copyright © 2016年 East. All rights reserved.
//

#import "DAUMonElectricityVC.h"
#import <YYWebImage.h>

@interface DAUMonElectricityVC ()

@property (weak, nonatomic) IBOutlet UIImageView *elecBgImageView;
@property (weak, nonatomic) IBOutlet UIImageView *elecImageView;
@property (weak, nonatomic) IBOutlet UILabel *elecValueLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewHeightConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewWidthConstraint;

@property (nonatomic, readonly) DAUColPowerModel *power_consumpsion;

@end

@implementation DAUMonElectricityVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self initSubViews];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self refreshWholeView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (DAUColPowerModel *)power_consumpsion {
    return DAU_APP_DELEGATE.dauModel.engineDetail.result.power_consumpsion;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)initSubViews {
    self.bgViewWidthConstraint.constant = DAU_SCREEN_WIDTH;
    self.bgViewHeightConstraint.constant = DAU_SCREEN_HEIGHT;
}

- (void)refreshWholeView {
    if (self.power_consumpsion.pic.length) {
        self.elecImageView.hidden = NO;
        self.elecImageView.image = [UIImage imageWithData:[[NSData alloc] initWithBase64EncodedString:self.power_consumpsion.pic options:NSDataBase64DecodingIgnoreUnknownCharacters]];
        
        self.elecImageView.layer.cornerRadius = (DAU_SCREEN_WIDTH - 30 * 2 - 20 * 2) / 2.0;
        //        self.elecImageView.layer.borderWidth = 20;
        //        self.elecImageView.layer.borderColor = DAU_COLOR_ElecBgBoard(1.0).CGColor;
        self.elecImageView.layer.masksToBounds = YES;
    } else {
        self.elecImageView.hidden = YES;
    }
    
    NSString *valueStr = [NSString stringWithFormat:@"%zd", self.power_consumpsion.value];
    NSString *str = [NSString stringWithFormat:@"%@kWh", valueStr];
    NSMutableAttributedString *mAStr = [[NSMutableAttributedString alloc] initWithString:str];
    [mAStr addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:35]}  // 原始字体是53
                   range:NSMakeRange(0, valueStr.length)];
    [mAStr addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:20]}  // 原始字体是26
                   range:NSMakeRange(valueStr.length, str.length - valueStr.length)];
    self.elecValueLabel.attributedText = mAStr;
}

@end
